<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width,initial-scale=1" />
    <title>博雅诗词管理系统</title>
    <!-- 最新版本的 Bootstrap 核心 CSS 文件 -->
    <link rel="stylesheet" href="/bootstrap/css/bootstrap.css" crossorigin="anonymous">

    <!-- 可选的 Bootstrap 主题文件（一般不用引入） -->
    <link rel="stylesheet" href="/bootstrap/css/bootstrap-theme.css" crossorigin="anonymous">

    <script src="/js/jquery-3.4.1.min.js" type="text/javascript" charset="utf-8"></script>
    <!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
    <script src="/bootstrap/js/bootstrap.js"></script>
    <link rel="stylesheet" th:href="@{/css/poem.css}">
</head>
<body>
    <!-- 导航 -->
    <nav class="navbar navbar-inverse navbar-fix-top" role="navigation">
        <div class="container" th:replace="fragments/header::header">
        </div>
    </nav>
    <div class="container">
        <div class="row">
            <div class="col-sm-4">
                <ul class="nav nav-list">
                    <li class="nav-header">
                        统计信息
                    </li>
                    <li class="active">
                        <a href="#">系统首页</a>
                    </li>
                    <li>
                        <a href="#">用户统计</a>
                    </li>
                    <li>
                        <a href="#">诗词统计</a>
                    </li>
                    <li class="nav-header">
                        审核管理
                    </li>
                    <li>
                        <a href="/admin/note/1">注释审核</a>
                    </li>
                    <li>
                        <a href="/admin/translate/1">译文审核</a>
                    </li>
                    <li>
                        <a href="/admin/appreciation/1">赏析审核</a>
                    </li>
                    <li>
                        <a href="/admin/story/1">故事审核</a>
                    </li>
                    <li class="divider">
                    </li>
                    <li>
                        <a href="#">系统帮助</a>
                    </li>
                </ul>
            </div>
            <div class="col-sm-8">

                <section th:each="poetry : ${poetries}">
                    <div class="panel" th:classappend="${poetry.verify}==0?'panel-danger':'panel-primary'">
                        <div class="panel-heading poem-title">
                            <h3 class="panel-title">
                                <a th:href="@{'/poetry/'+${poetry.id}}" th:text="${poetry.title}" target="_blank">静夜思</a></h3>
                        </div>
                        <div class="panel-body">
                            <div id="poetry-body">
                                <span th:text="${poetry.content}">
                                窗前明月光，疑是地上霜。<br>
                                举头望明月，低头思故乡。
                                </span>
                            </div>

                            <h5 class="page-header"></h5>

                            <button type="button" class="btn btn-default btn-xs active btn-verify" th:attr="pid=${poetry.id}" th:if="${poetry.verify}==0">审核通过</button>
                            <button type="button" class="btn btn-default btn-xs active btn-verify" th:attr="pid=${poetry.id}" th:if="${poetry.verify}!=0">取消审核</button>
                            <button type="button" class="btn btn-default btn-xs active btn-delete" th:attr="pid=${poetry.id}">删除译文</button>
                        </div>
                    </div>
                </section>

                <!-- 分页 -->
                <nav th:if="${authorId}==null">
                    <ul class="pagination pagination-lg">
                        <li th:class="${pageCurrent==1?'disabled':''}"><a th:href="@{'/admin/translate/'+${pageCurrent-1}}">&laquo;</a></li>
                        <th:block th:each="p : ${pages}">
                            <li th:class="${p==pageCurrent?'active':''}"><a th:href="${'/admin/translate/'+p}" th:text="${p}">3</a></li>
                        </th:block>
                        <li th:class="${pageCurrent==pageCount?'disabled':''}"><a th:href="@{'/admin/translate/'+${pageCurrent+1}}">&raquo;</a></li>
                    </ul>
                </nav>
            </div>
            </div>
        </div>
    </div>
    <div th:replace="fragments/footer::footer"></div>
    <script type="text/javascript">
        $(function () {
            //-- 审核/取消审核
            $(".btn-verify").on('click',function() {
                console.log("verify....")
                var pid = $(this).attr("pid");
                var self = $(this);

                var param = {};
                param.id = pid;

                $.post("/admin/doTranslateVerify",param,function(result){
                    console.log(result);
                    if(result.result == 0) {
                        if(result.data.verify > 0) {
                            self.text("取消审核")
                            self.parent().parent().removeClass("panel-danger");
                            self.parent().parent().addClass("panel-primary");
                        }
                        else {
                            self.text("审核通过")
                            self.parent().parent().removeClass("panel-primary");
                            self.parent().parent().addClass("panel-danger");
                        }
                        console.log(result.data);
                    }
                });

            });

            //-- 删除
            $(".btn-delete").on('click',function() {
                console.log("delete....")
                var pid = $(this).attr("pid");
                var self = $(this);

                if(confirm("确定删除该吗?")){
                    //点击确定后操作
                    console.log("删除....");
                    var param = {};
                    param.id = pid;

                    $.post("/admin/doTranslateDelete",param,function(result){
                        console.log(result);
                        if(result.result == 0) {
                            console.log("删对了吗");
                            self.parent().parent().parent().remove();
                        }
                    });
                }
            });
        });
    </script>
</body>
</html>